import { Provide } from '@midwayjs/decorator';
import { CoolController, BaseController } from 'midwayjs-cool-core';
import { Context } from 'vm';
import { classgroupEntity } from '../../../classgroup/entity/classgroup';
import { studentEntity } from '../../../student/entity/student';
import { classgroupStudentsEntity } from '../../entity/classgroupStudents';
import { classgroupStudentsService } from '../../service/classgroupStudents';

/**
 * 描述
 */
@Provide()
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: classgroupStudentsEntity,
  service:classgroupStudentsService,
  pageQueryOp:{ 
    // 让title字段支持模糊查询
    // keyWordLikeFields: ['a.class_name'],
    // 让type字段支持筛选
    fieldEq: ['classgroup_id'],
    // 指定返回字段
    select: ['a.*'],
    // // 关联表用户表
    leftJoin: [{
      entity: classgroupEntity,
      alias: 'b',
      condition: 'a.classgroup_id = b.id'
    }],
    where: async (ctx: Context) => { 
      return [ 
        ['a.isDelete = :isDelete', { isDelete: false }] 
      ] 
    } 
  },
  listQueryOp:{ 
    // 让type字段支持筛选
    fieldEq: ['classgroup_id'],
    // 指定返回字段
    select: ['a.*','c.name'],
    // // 关联表用户表
    leftJoin: [
      {
      entity: classgroupEntity,
      alias: 'b',
      condition: 'a.classgroup_id = b.id'
    },
    {
      entity: studentEntity,
      alias: 'c',
      condition: 'a.student_id = c.id'
    },
  ],
    where: async (ctx: Context) => { 
      return [ 
        ['a.isDelete = :isDelete', { isDelete: false }] 
      ] 
    } 
  }
})
export class classgroupStudentsController extends BaseController {}
